{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Please input your directory for the top level folder\n",
    "folder name : SUBMISSION MODEL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "dir_ = \"INPUT-PROJECT-DIRECTORY/submission_model/\"  # input only here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### setting other directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "raw_data_dir = dir_ + \"2. data/\"\n",
    "processed_data_dir = dir_ + \"2. data/processed/\"\n",
    "log_dir = dir_ + \"4. logs/\"\n",
    "model_dir = dir_ + \"5. models/\"\n",
    "submission_dir = dir_ + \"6. submissions/\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "submission = pd.read_csv(raw_data_dir + \"sample_submission.csv\")\n",
    "ids = pd.DataFrame({\"id\": submission.iloc[30490:][\"id\"]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "quantiles = [\n",
    "    \"0.025\",\n",
    "    \"0.750\",\n",
    "    \"0.250\",\n",
    "    \"0.995\",\n",
    "    \"0.165\",\n",
    "    \"0.835\",\n",
    "    \"0.005\",\n",
    "    \"0.975\",\n",
    "    \"0.500\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "for quantile in list(set(quantiles)):\n",
    "    sub1 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_recursive_store_{quantile}.csv\"\n",
    "    )\n",
    "    sub2 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_recursive_store_cat_{quantile}.csv\"\n",
    "    )\n",
    "    sub3 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_recursive_store_dept_{quantile}.csv\"\n",
    "    )\n",
    "\n",
    "    sub4 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_nonrecursive_store_{quantile}.csv\"\n",
    "    )\n",
    "    sub5 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_nonrecursive_store_cat_{quantile}.csv\"\n",
    "    )\n",
    "    sub6 = pd.read_csv(\n",
    "        submission_dir\n",
    "        + f\"before_ensemble/submission_kaggle_nonrecursive_store_dept_{quantile}.csv\"\n",
    "    )\n",
    "    sub1 = ids.merge(sub1, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "    sub2 = ids.merge(sub2, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "    sub3 = ids.merge(sub3, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "\n",
    "    sub4 = ids.merge(sub4, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "    sub5 = ids.merge(sub5, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "    sub6 = ids.merge(sub6, on=\"id\", how=\"left\").set_index(\"id\")\n",
    "    final_sub = (sub1 + sub2 + sub3 + sub4 + sub5 + sub6) / 6\n",
    "    final_sub.to_csv(\n",
    "        submission_dir + f\"submission_final_{quantile}_non_recursive.csv\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/ec2-user/SageMaker/efs/Hilaf/repos/QRX-wrap/M5-methods/submission_model/6. submissions/'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submission_dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "conda_mxnet_p36",
   "language": "python",
   "name": "conda_mxnet_p36"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
